#coding=utf-8
import MySQLdb
from consts import HOSTNAME,DATABASE,USERNAME,PASSWORD
def checkUser(username,password):
    # cur.execute("insert into admin(uid,username,password) values(1,'admin','12346')")#insert data
    con = MySQLdb.connect(HOSTNAME,USERNAME,PASSWORD,DATABASE)
    cur = con.cursor()
    cur.execute("select password from admin where username='%s'"%username)
    dbpasswd = cur.fetchone()[0]
    if dbpasswd == password:
        return 1
    else:
        return 0

def getapplist():
    con = MySQLdb.connect(HOSTNAME,USERNAME,PASSWORD,DATABASE)
    cur = con.cursor()
    sql = "select appname from app"
    cur.execute(sql)
    applist = cur.fetchall()
    info=[]
    for i in applist:
        info.append(i[0])
    return info